home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 3 of 3 / CHAPTE10 / GETREQST / LINE.C < prev    next >
C/C++ Source or Header  |  1996-04-28  |  28KB  |  860 lines

  1.  
  2. #include <windows.h> 
  3. #include <windowsx.h> 
  4. #include "line.h" 
  5. #include "tapi.h"
  6.  
  7. #define BUFSIZE 256
  8. #define APIHIVERSION     0x00010028    /* 1.40 */
  9. #define APILOWVERSION    0x00010000    /* 1.0 */
  10. #define EXTHIVERSION     0x00010005    /* 1.5 */
  11. #define EXTLOWVERSION    0x00000009    /* 0.9 */ 
  12. #define OWNER        0
  13. #define MONITOR      1
  14. #define MAX_CALL        3
  15. #define MAX_LINE        2
  16.  
  17.  
  18. #if defined (WIN32)
  19.     #define IS_WIN32 TRUE
  20. #else
  21.     #define IS_WIN32 FALSE
  22. #endif
  23.  
  24. #define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
  25. #define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
  26. #define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
  27.  
  28. LPCTSTR lpszAppName = "lineGetRequest";
  29. LPCTSTR lpszTitle   = "lineGetRequest"; 
  30.  
  31. HINSTANCE hInst;   // current instance
  32. HWND hWnd;         // parent window handle
  33. HWND hListWnd;     // listbox
  34. HDC  hdc;
  35. TEXTMETRIC  tm ;
  36.  
  37. BOOL RegisterWin95( CONST WNDCLASS* lpwc );
  38.  
  39.  
  40. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  41.                       LPTSTR lpCmdLine, int nCmdShow)
  42. {
  43.    MSG      msg;
  44.    WNDCLASS wc;
  45.  
  46.    wc.style         = CS_HREDRAW | CS_VREDRAW;
  47.    wc.lpfnWndProc   = (WNDPROC)WndProc;       
  48.    wc.cbClsExtra    = 0;                      
  49.    wc.cbWndExtra    = 0;                      
  50.    wc.hInstance     = hInstance;              
  51.    wc.hIcon         = LoadIcon (hInstance, lpszAppName); 
  52.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  53.    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  54.    wc.lpszMenuName  = lpszAppName;              
  55.    wc.lpszClassName = lpszAppName;              
  56.  
  57.    if ( IS_WIN95 )
  58.    {
  59.       if ( !RegisterWin95( &wc ) )
  60.          return( FALSE );
  61.    }
  62.    else if ( !RegisterClass( &wc ) )
  63.       return( FALSE );
  64.  
  65.    hInst = hInstance; 
  66.  
  67.    hWnd = CreateWindow( lpszAppName, 
  68.                         lpszTitle,    
  69.                         WS_OVERLAPPEDWINDOW, 
  70.                         CW_USEDEFAULT, 0, 
  71.                         CW_USEDEFAULT, 0,  
  72.                         NULL,              
  73.                         NULL,              
  74.                         hInstance,         
  75.                         NULL               
  76.                       );
  77.  
  78.    if ( !hWnd ) 
  79.       return( FALSE );
  80.  
  81.    ShowWindow( hWnd, nCmdShow ); 
  82.    UpdateWindow( hWnd );         
  83.  
  84.    while( GetMessage( &msg, NULL, 0, 0) )   
  85.    {
  86.       TranslateMessage( &msg ); 
  87.       DispatchMessage( &msg );  
  88.    }
  89.  
  90.    return( msg.wParam ); 
  91. }
  92.  
  93.  
  94. BOOL RegisterWin95( CONST WNDCLASS* lpwc )
  95. {
  96.     WNDCLASSEX wcex;
  97.  
  98.    wcex.style         = lpwc->style;
  99.    wcex.lpfnWndProc   = lpwc->lpfnWndProc;
  100.    wcex.cbClsExtra    = lpwc->cbClsExtra;
  101.    wcex.cbWndExtra    = lpwc->cbWndExtra;
  102.    wcex.hInstance     = lpwc->hInstance;
  103.    wcex.hIcon         = lpwc->hIcon;
  104.    wcex.hCursor       = lpwc->hCursor;
  105.    wcex.hbrBackground = lpwc->hbrBackground;
  106.    wcex.lpszMenuName  = lpwc->lpszMenuName;
  107.    wcex.lpszClassName = lpwc->lpszClassName;
  108.  
  109.    // Added elements for Windows 95.
  110.    //...............................
  111.    wcex.cbSize = sizeof(WNDCLASSEX);
  112.    wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName, 
  113.                             IMAGE_ICON, 16, 16,
  114.                             LR_DEFAULTCOLOR );
  115.             
  116.    return RegisterClassEx( &wcex );
  117. }
  118.  
  119. #define CONFCALL    1
  120. #define CONSULT      2
  121.  
  122. enum CallState
  123. {
  124.     Idle,
  125.     Offering,
  126.     Accepted,
  127.     Dialtone,
  128.     Dialing,
  129.     Ringback,
  130.     Busy,
  131.     Special,
  132.     Connected,
  133.     Proceeding,
  134.     Conferenced,
  135.     Onholdconf,
  136.     Disconnected,
  137.     Unknown
  138. };
  139.  
  140. typedef struct tagMYINFO      // general application information
  141. {
  142.     HLINEAPP lineApp;         // instance handle TAPI gives back to us                                                                              through lineInitialize()
  143.     DWORD dwNumDevices;       // number of available devices
  144.     DWORD dwAPIVersion;       // API version the line supports
  145.      DWORD dwExtVersion;           // extended version
  146.     char  szProvider[128];    // place holder for provider name
  147. } MYINFO;
  148.  
  149. typedef struct tagLINEINFO  // information on an open line
  150. {
  151.     DWORD dwNumAddress;     // number of available addresses on the line 
  152.     HLINE hLine;            // handle to the line as returned by lineOpen 
  153.      DWORD dwLineID;         // the line ID of this line
  154.     char  szLineName[128];  // the line's name 
  155.  
  156. } MYLINEINFO;
  157.  
  158. typedef struct tagMYCALLINFO  //information on a call                     
  159. {
  160.     
  161. DWORD       eCallState;    // TAPI's line call State, set as user-defined enums
  162. DWORD      dwRequestID;   // requestID returned by async TAPI functions lineMakeCall/lineDropCall
  163. DWORD      dwAddressID;   // the originating address ID of the call being made 
  164. LPCSTR     lpszAddress;    
  165. HLINE     hLine;         // handle to the line 
  166. HCALL        hCall;         // handle to the call 
  167.    
  168. char szDialString[TAPIMAXDESTADDRESSSIZE];  //phone number being dialed
  169. char szDialStringOriginal[TAPIMAXDESTADDRESSSIZE];
  170. char szDialStringCanonical[TAPIMAXDESTADDRESSSIZE];
  171. char szCalledParty[TAPIMAXCALLEDPARTYSIZE]; // name of the party
  172. DWORD dwTranslateResults;
  173.         
  174. } MYCALLINFO;
  175.  
  176. enum CallAction     // Declare enum type CallAction (used in lineSetAppSpecific)
  177. {
  178.    HOLD,            // hold the call
  179.    TRANSFER,        // transfer the call
  180.    REDIRECT,        // redirect the call
  181.    DROP,            // drop the call
  182.    PARK             // park the call
  183. }; 
  184.  
  185. MYINFO myInfo;          //instance of MYINFO structure
  186. MYLINEINFO myLineInfo[MAX_LINE];  //instance of MYLINEINFO structure
  187. MYCALLINFO myCallInfo[MAX_CALL]; //array of MYCALLINFO strcuture
  188.  
  189. LONG lRet;        //return code
  190. char buf[BUFSIZE];    // buffer for debug message
  191.  
  192. DWORD dwLineID = 0;
  193. DWORD i;
  194. LINEEXTENSIONID        ext_id;
  195. LINEDEVCAPS            *plineDevCaps;
  196. LINEADDRESSCAPS        *plineAddressCaps;
  197. LINEADDRESSSTATUS     *plineAddressStat;
  198. LINECALLINFO            *plineCallInfo;
  199. LINECALLSTATUS         *plineCallStatus;
  200. LINECALLLIST            *plineCallList;
  201. LINEDEVSTATUS           *plineDevStatus;
  202. LINETRANSLATECAPS       *plineTranslateCaps;
  203. LINETRANSLATEOUTPUT  *plineTranslateOutput;
  204. LINECALLPARAMS           *plineCallParams;
  205. LINEDEVSTATUS           *plineDevStatus;
  206. LINEFORWARDLIST        *plineForwardList;
  207. LINETRANSLATECAPS       *plineTranslateCaps;
  208. LINEREQMAKECALL       lineReqMakeCall;
  209.  
  210. LPLINEPROVIDERENTRY  lineProviderEntry;
  211. VARSTRING               *pDeviceConfig;
  212. VARSTRING               *pDeviceId;
  213. VARSTRING               *pNonDirAddress;
  214.  
  215. LPLINELOCATIONENTRY  lineLocEntry;
  216. LPLINECARDENTRY        lineCardEntry;
  217. LINECOUNTRYLIST         *plineCountryList;
  218. LPLINECOUNTRYENTRY   lineCE;
  219.  
  220.  
  221. LINEPROVIDERLIST     *plineProviderList;
  222.  
  223. LPSTR                lpData;
  224.  
  225. HICON                hIcon = NULL;        //used in lineGetID();
  226. DWORD                dwNumRings;    //used in lineGetNumRings();
  227. HCALL                hConsultCall; //handle to consultation linePrepareAddToConference, SetupConference
  228. HCALL                hConfCall; //handle to consultation linePrepareAddToConference, SetupConference   
  229. HCALL                hParkedCall;
  230. DWORD          dwProviderID; // id of provider to add
  231.  
  232.  
  233. DWORD          dwAppPriority; //return the application priority
  234.  
  235. char                szName[128];
  236. char                szNumber[128];
  237. char                szDigits[128];
  238. char                szDevConfig[128];
  239.  
  240. LONG lRet;
  241. char buf[BUFSIZE];
  242.  
  243. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  244. {
  245.    switch( uMsg )
  246.    {
  247.       case WM_COMMAND :
  248.          switch( LOWORD( wParam ) )
  249.          {
  250.              case IDM_RUN :
  251.              {
  252.                   lRet = lineRegisterRequestRecipient(myInfo.lineApp, (DWORD)lineCallback, 
  253.                                     LINEREQUESTMODE_MAKECALL, TRUE);
  254.                if (lRet == 0)
  255.                   {
  256.                   wsprintf (buf, "This application is registered as a request recipient!");
  257.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  258.              
  259.                   lRet = lineSetAppPriority("lineGetRequest", 0, 0, LINEREQUESTMODE_MAKECALL, NULL, 1);
  260.                   
  261.                   if (lRet == 0)
  262.                   {
  263.                      wsprintf (buf, "lineSetAppPriority succeeded");                                     
  264.                      SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  265.  
  266.                      lRet =  lineGetAppPriority("lineGetRequest", 0, 0, LINEREQUESTMODE_MAKECALL, NULL, &dwAppPriority);
  267.                      wsprintf ( buf,"This applications priority for Assisted Telephony is: x%lx", dwAppPriority);
  268.                      SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  269.                   }
  270.                   else
  271.                   {
  272.                           wsprintf ( buf,"lineSetAppPriority failed, err=x%lx", lRet);
  273.                           lineError(lRet);
  274.                          break;
  275.                   }
  276.                }
  277.                   else 
  278.                   {
  279.                        wsprintf ( buf,"lineRegisterRequestRecipient failed, err=x%lx", lRet);
  280.                        lineError(lRet);
  281.                       break;
  282.                }
  283.                   break;                      
  284.             }                 
  285.              
  286.             case IDM_ABOUT :
  287.             {
  288.                 DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
  289.                break;
  290.             }
  291.  
  292.             case IDM_EXIT :
  293.             {
  294.                for (i = 0; i < myInfo.dwNumDevices; i++)
  295.                        lineClose(myLineInfo[i].hLine);
  296.                     lineShutdown(myInfo.lineApp);
  297.                DestroyWindow( hWnd );
  298.                break;
  299.             }
  300.             }                  
  301.                  
  302.          break;
  303.  
  304.       case WM_CREATE :
  305.       {
  306.          hdc = GetDC (hWnd) ;
  307.          GetTextMetrics (hdc, &tm) ;
  308.          ReleaseDC (hWnd, hdc) ;
  309.  
  310.          hListWnd = CreateWindowEx( 0, "listbox", 
  311.                         " ",    
  312.                         WS_CHILD | WS_VISIBLE,  
  313.                         tm.tmAveCharWidth, tm.tmHeight * 3, 
  314.                         tm.tmAveCharWidth * 16 +
  315.                                    GetSystemMetrics (SM_CXVSCROLL), 
  316.                         tm.tmHeight * 5,  
  317.                         hWnd,              
  318.                         NULL,              
  319.                         hInst,         
  320.                         NULL               
  321.                         );
  322.  
  323.          
  324.          //lineInitialize
  325.             //...............................................
  326.          lRet = lineInitialize(&myInfo.lineApp, hInst, lineCallback, NULL, &myInfo.dwNumDevices);
  327.          if (lRet == 0) 
  328.          {
  329.             wsprintf (buf, "lineInitialize suceeded!");
  330.               SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  331.            }
  332.          else 
  333.           {
  334.                wsprintf ( buf,"lineInitialize failed, err=x%lx",lRet);
  335.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  336.                lineError(lRet);
  337.                break;
  338.          }                    
  339.          
  340.          //lineNegotiateAPIVersion
  341.           //...............................................
  342.          lRet = lineNegotiateAPIVersion(myInfo.lineApp, 0, APILOWVERSION, APIHIVERSION, 
  343.                                            &myInfo.dwAPIVersion, &ext_id);
  344.          if (lRet == 0)                        
  345.          {
  346.             wsprintf (buf, "lineNegotiateAPIVersion suceeded!");
  347.               SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  348.          }
  349.          else 
  350.           {
  351.                wsprintf (buf, "lineNegotiateAPIVersion failed, err=x%lx",
  352.                            lRet);
  353.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  354.                lineError(lRet);
  355.                lineShutdown (myInfo.lineApp);
  356.             break;
  357.          }
  358.  
  359.           //lineNegotiateExtVersion
  360.           //...............................................
  361.          lRet = lineNegotiateExtVersion(myInfo.lineApp, 0, myInfo.dwAPIVersion, EXTLOWVERSION, 
  362.                                            EXTHIVERSION, &myInfo.dwExtVersion);
  363.          if (lRet == 0)                        
  364.          {
  365.             wsprintf (buf, "lineNegotiateExtVersion suceeded!");
  366.             SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  367.  
  368.          }
  369.           else 
  370.           {
  371.                wsprintf (buf, "lineNegotiateExtVersion failed, err=x%lx",
  372.                      lRet);
  373.               SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  374.               lineError(lRet);
  375.       
  376.          }
  377.  
  378.           //lineGetDevCaps
  379.           //for each line device, get capabilities until we find one that supports
  380.          //interactive voice 
  381.           //...............................................
  382.          plineDevCaps = (LINEDEVCAPS *) calloc (1, sizeof(LINEDEVCAPS)+1000);
  383.          plineDevCaps->dwTotalSize = sizeof(LINEDEVCAPS) + 1000;
  384.          for (i = 0; i < myInfo.dwNumDevices; i++)
  385.          {
  386.             lineGetDevCaps(myInfo.lineApp, i, myInfo.dwAPIVersion, 0, plineDevCaps);
  387.             if (plineDevCaps->dwMediaModes & LINEMEDIAMODE_INTERACTIVEVOICE) 
  388.             {
  389.                
  390.                myLineInfo[i].dwNumAddress = plineDevCaps->dwNumAddresses;
  391.                   myLineInfo[i].dwLineID = i;
  392.                    if (plineDevCaps->dwLineNameSize > 0)
  393.                           strcpy(myLineInfo[i].szLineName,((LPSTR)(plineDevCaps)+plineDevCaps->dwLineNameOffset));
  394.              }
  395.           }
  396.  
  397.          //lineOpen
  398.           //................................................................
  399.           lRet = lineOpen(myInfo.lineApp,myLineInfo[OWNER].dwLineID,&myLineInfo[OWNER].hLine,
  400.                            myInfo.dwAPIVersion,0,(DWORD)lineCallback, LINECALLPRIVILEGE_NONE,
  401.                             LINEMEDIAMODE_DATAMODEM, NULL);
  402.           if (lRet == 0)
  403.           {
  404.             wsprintf (buf, "lineOpen suceeded!");
  405.             SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;         }
  406.            else 
  407.            {
  408.                wsprintf ( buf,"lineOpen failed, err=x%lx", lRet);
  409.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  410.                lineError(lRet);
  411.           }
  412.        
  413.          break;
  414.       }
  415.       
  416.       case WM_SIZE:
  417.           MoveWindow(hListWnd,0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
  418.          break;
  419.  
  420.       case WM_DESTROY :
  421.               PostQuitMessage(0);
  422.               break;
  423.  
  424.       default :
  425.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  426.    }
  427.  
  428.    return( 0L );
  429. }
  430.  
  431.  
  432.  
  433. /****************************************************************************
  434.     FUNCTION: lineCallback
  435.     PURPOSE:  callback function handles line events
  436. ****************************************************************************/
  437. LRESULT CALLBACK lineCallback (DWORD dwDevice, DWORD dwMsg,
  438.                                        DWORD dwCallbackInst, DWORD dwParam1,
  439.                                        DWORD dwParam2,DWORD dwParam3)
  440. {
  441.    switch (dwMsg)
  442.    {
  443.       case LINE_CALLSTATE:
  444.        {
  445.             for (i = 0; i < MAX_CALL; i++)
  446.            {
  447.                 if (dwDevice = (DWORD) myCallInfo[i].hCall) 
  448.                  switch (dwParam1)
  449.                  {
  450.                     case LINECALLSTATE_IDLE:
  451.                         myCallInfo[i].eCallState = Idle;
  452.                   break;
  453.                     
  454.                     case LINECALLSTATE_OFFERING:
  455.                   myCallInfo[i].eCallState = Offering;
  456.                   break;
  457.                                    
  458.                     case LINECALLSTATE_ACCEPTED:
  459.                         myCallInfo[i].eCallState = Accepted;
  460.                         break;
  461.                     
  462.                     case LINECALLSTATE_DIALTONE:
  463.                         myCallInfo[i].eCallState = Dialtone;
  464.                   break;
  465.                     
  466.                     case LINECALLSTATE_DIALING:
  467.                         myCallInfo[i].eCallState = Dialing;
  468.                         break;
  469.                   
  470.                   case LINECALLSTATE_RINGBACK:
  471.                         myCallInfo[i].eCallState = Ringback;
  472.                         break;
  473.             
  474.                     case LINECALLSTATE_BUSY:
  475.                         myCallInfo[i].eCallState = Busy;
  476.                         break;
  477.             
  478.                     case LINECALLSTATE_SPECIALINFO:
  479.                         myCallInfo[i].eCallState = Special;
  480.                        break;
  481.             
  482.                     case LINECALLSTATE_CONNECTED:
  483.                        myCallInfo[i].eCallState = Connected;
  484.                   break;
  485.  
  486.                     case LINECALLSTATE_PROCEEDING:
  487.                         myCallInfo[i].eCallState = Proceeding;
  488.                        break;
  489.             
  490.                     case LINECALLSTATE_CONFERENCED:
  491.                         myCallInfo[i].eCallState = Conferenced;
  492.                        break;
  493.             
  494.                     case LINECALLSTATE_ONHOLDPENDCONF:
  495.                         break;
  496.                 
  497.                case LINECALLSTATE_DISCONNECTED:
  498.                         myCallInfo[i].eCallState = Disconnected;
  499.                        break;
  500.             
  501.                     case LINECALLSTATE_UNKNOWN:
  502.                         myCallInfo[i].eCallState = Unknown;
  503.                        break;
  504.        
  505.              }
  506.           }
  507.        }
  508.  
  509.     case LINE_REQUEST:
  510.     {
  511.       if (dwParam1 == LINEREQUESTMODE_MAKECALL)
  512.       {
  513.              LineCheckRequests();
  514.              break;
  515.       }
  516.     }
  517.  
  518.        //error handling for functions completed asynchronously
  519.         //.....................................................
  520.        case LINE_REPLY:
  521.         {
  522.             for (i = 0; i < MAX_CALL; i++)
  523.            {
  524.                 if (dwParam1 = myCallInfo[i].dwRequestID)
  525.                {
  526.                    if (dwParam2 != 0)
  527.                    {
  528.                        lineError((LONG) dwParam2);
  529.                        break;
  530.                    }
  531.                }
  532.            }
  533.         break;
  534.         }
  535.  
  536.         case LINE_GENERATE:
  537.           break;
  538.      
  539.  
  540.         case LINE_GATHERDIGITS:
  541.            break;
  542.    }
  543.  
  544.    return (TRUE);
  545.  
  546.  
  547. /****************************************************************************
  548.     FUNCTION: lineError
  549.     PURPOSE:  line error messages
  550. ****************************************************************************/
  551. void lineError (LONG lrc)
  552. {
  553.  switch (lrc) {
  554.     case LINEERR_INVALAPPHANDLE:
  555.        MessageBox (hWnd, "Invalid app handle.", "", MB_OK);
  556.        break;
  557.     case LINEERR_BADDEVICEID:
  558.        MessageBox (hWnd,"The specified line device ID is out of range.", "", 
  559.                    MB_OK);
  560.        break;
  561.     case LINEERR_INCOMPATIBLEAPIVERSION:
  562.        MessageBox (hWnd, "Incompatible API version.", "", MB_OK);
  563.        break;
  564.     
  565.     case LINEERR_ADDRESSBLOCKED:
  566.        MessageBox (hWnd, "Address was blocked.", "", MB_OK);
  567.        break;
  568.  
  569.     case LINEERR_BEARERMODEUNAVAIL:
  570.        MessageBox (hWnd, "Bearer Mode Unavailable.", "", MB_OK);
  571.        break;
  572.  
  573.     case LINEERR_CALLUNAVAIL:
  574.        MessageBox (hWnd, "Call appearances in use..", "", MB_OK);
  575.        break;
  576.  
  577.     case LINEERR_INUSE:
  578.        MessageBox (hWnd, "Line in Use.", "", MB_OK);
  579.        break;
  580.     
  581.     case LINEERR_INVALADDRESS:
  582.        MessageBox (hWnd, "Invalid Address.", "", MB_OK);
  583.        break;
  584.  
  585.     case LINEERR_INVALADDRESSID:
  586.        MessageBox (hWnd, "Invalid Address ID.", "", MB_OK);
  587.        break;
  588.  
  589.     case LINEERR_INVALCALLPARAMS:
  590.        MessageBox (hWnd, "Invalid Address ID.", "", MB_OK);
  591.        break;
  592.      
  593.     case LINEERR_INCOMPATIBLEEXTVERSION:
  594.        MessageBox (hWnd, "Incompatible extension version.","", MB_OK);
  595.        break;
  596.     case LINEERR_NOMEM:
  597.        MessageBox (hWnd, "No memory","", MB_OK);
  598.        break;
  599.     case LINEERR_NODRIVER:
  600.        MessageBox (hWnd, "No driver loaded", "", MB_OK);
  601.        break;
  602.     case LINEERR_RESOURCEUNAVAIL:
  603.        MessageBox (hWnd, "Resource overcommittment", "", MB_OK);
  604.        break;
  605.     case LINEERR_INVALPRIVSELECT:
  606.        MessageBox (hWnd, "Requested invalid priviledges", "", MB_OK);
  607.        break;
  608.     case LINEERR_INVALMEDIAMODE:
  609.        MessageBox (hWnd, "Requested invalid media mode", "", MB_OK);
  610.        break;
  611.     case LINEERR_LINEMAPPERFAILED:
  612.        MessageBox (hWnd, "Line mapper failed", "", MB_OK);
  613.        break;
  614.     case LINEERR_INVALPOINTER:
  615.        MessageBox (hWnd, "The specified pointer parameter is invalid.",
  616.                    "", MB_OK);
  617.        break;
  618.     case LINEERR_OPERATIONFAILED:
  619.        MessageBox (hWnd, "Operation failed.", "", MB_OK);
  620.        break;
  621.     case LINEERR_INVALLINEHANDLE:
  622.        MessageBox (hWnd, "Invalid line handle", "", MB_OK);
  623.        break;
  624.     case LINEERR_INVALCALLHANDLE:
  625.        MessageBox (hWnd, "Invalid call handle", "", MB_OK);
  626.        break;
  627.     case LINEERR_INVALCALLSELECT:
  628.        MessageBox (hWnd, "Invalid call selection", "", MB_OK);
  629.        break;
  630.     case LINEERR_NODEVICE:
  631.        MessageBox (hWnd, "No associated device for given class",
  632.                    "", MB_OK);
  633.        break;
  634.     case LINEERR_OPERATIONUNAVAIL:
  635.        MessageBox (hWnd, "The operation is unavailable",
  636.                    "", MB_OK);
  637.        break;
  638.     case LINEERR_INVALPARAM:
  639.         MessageBox(hWnd, "Invalid Paramater", "", MB_OK);
  640.        break; 
  641.  
  642.     case LINEERR_TARGETNOTFOUND:
  643.         MessageBox(hWnd, "Target Not Found", "", MB_OK);
  644.        break; 
  645.  
  646.    case LINEERR_NOREQUEST:
  647.       MessageBox(hWnd, "No outstanding Assisted Telephony requests.", "", MB_OK);
  648.        break; 
  649.    }
  650. }
  651.  
  652. VOID MakeaCall()
  653. {
  654.    //lineMakeCall
  655.     //................................................................
  656.                           
  657.     plineCallParams = (LINECALLPARAMS *) calloc (1, sizeof(LINECALLPARAMS)+1000);
  658.    plineCallParams->dwTotalSize = sizeof(LINECALLPARAMS) + 1000;
  659.  
  660.     plineCallParams->dwBearerMode = LINEBEARERMODE_VOICE;
  661.     plineCallParams->dwMediaMode =  LINEMEDIAMODE_DATAMODEM;
  662.     plineCallParams->dwCallParamFlags = LINECALLPARAMFLAGS_IDLE;
  663.     plineCallParams->dwAddressMode    = LINEADDRESSMODE_ADDRESSID;
  664.     plineCallParams->dwAddressID    = 0;
  665.     plineCallParams->dwMinRate    = 1200;
  666.     plineCallParams->dwMaxRate    = 14400;
  667.                             
  668.     
  669.     //show dialog to user
  670.    //........................
  671.     if (DialogBox( hInst, "IDD_ASSIST", hWnd, (DLGPROC)Assist ) == IDOK)
  672.    {
  673.        lRet = lineMakeCall(myLineInfo[OWNER].hLine,&myCallInfo[0].hCall, 
  674.                               myCallInfo[0].szDialString ,0,  plineCallParams);
  675.            
  676.       if (lRet > 0)
  677.        {
  678.          wsprintf (buf, "lineMakeCall proceeding!");
  679.            myCallInfo[0].dwRequestID = lRet;
  680.          SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  681.       }
  682.       else 
  683.       {
  684.          wsprintf ( buf,"lineMakeCall failed, err=x%lx", lRet);
  685.            lineError(lRet);
  686.        }
  687.    }  
  688. }
  689.  
  690. VOID LineCheckRequests()              
  691. {    
  692.  
  693.    lRet = lineGetRequest(myInfo.lineApp, LINEREQUESTMODE_MAKECALL, &lineReqMakeCall);
  694.       
  695.    if (lRet == 0)
  696.    {
  697.       strncpy(myCallInfo[0].szDialString, lineReqMakeCall.szDestAddress, sizeof(lineReqMakeCall.szDestAddress)); 
  698.       MakeaCall();
  699.    }
  700.    else
  701.       lineError(lRet);
  702. }
  703.  
  704. LRESULT CALLBACK Dial ( HWND hDlg,           // window handle of the dialog box
  705.                         UINT message,        // type of message
  706.                         WPARAM wParam,       // message-specific information
  707.                         LPARAM lParam)
  708. {
  709.    switch (message) 
  710.    {
  711.        case WM_INITDIALOG:  // message: initialize dialog box
  712.                return (TRUE);
  713.  
  714.        case WM_COMMAND:                              // message: received a command
  715.          if (   LOWORD(wParam) == IDOK )        // "OK" box selected?
  716.          {
  717.             GetDlgItemText(hDlg, IDC_NAME, szName, 128);
  718.                 GetDlgItemText(hDlg, IDC_NUMBER, szNumber, 128);
  719.                                       
  720.  
  721.                 // put up a dialog box to obtain a string to dial from the user
  722.                //...........................................................
  723.                strcpy(myCallInfo[0].szDialStringOriginal, szNumber); 
  724.                
  725.                //allocate buffer for the LINEADDRESSCAPS strucuture 
  726.                //...................................................
  727.                plineTranslateOutput = (LINETRANSLATEOUTPUT *) calloc (1, sizeof(LINETRANSLATEOUTPUT)+1000);
  728.             plineTranslateOutput->dwTotalSize = sizeof(LINETRANSLATEOUTPUT) + 1000;
  729.               
  730.                // translate the Address to a dialable address and Canonical address
  731.                //.....................................................................
  732.                lRet = lineTranslateAddress(myInfo.lineApp, myLineInfo[OWNER].dwLineID, myInfo.dwAPIVersion,
  733.                                            myCallInfo[0].szDialStringOriginal, 0, 0, plineTranslateOutput);
  734.                               
  735.                if (lRet == 0)
  736.                {
  737.                        
  738.                    strncpy(myCallInfo[0].szDialString, (LPSTR)(plineTranslateOutput)
  739.                             + plineTranslateOutput->dwDialableStringOffset,
  740.                              plineTranslateOutput->dwDialableStringSize); 
  741.     
  742.                     strncpy(myCallInfo[0].szDialStringCanonical,(LPSTR)(plineTranslateOutput) 
  743.                             + plineTranslateOutput->dwDisplayableStringOffset,
  744.                             plineTranslateOutput->dwDisplayableStringSize); 
  745.                                            
  746.                    myCallInfo[0].dwTranslateResults = plineTranslateOutput->dwTranslateResults;
  747.                 }
  748.  
  749.                else 
  750.                {
  751.                     wsprintf ( buf,"lineTranslateAddress failed, err=x%lx", lRet);
  752.                     lineError(lRet);
  753.                    break;
  754.             }
  755.            
  756.                //lineMakeCall
  757.                //................................................................
  758.                           
  759.                plineCallParams = (LINECALLPARAMS *) calloc (1, sizeof(LINECALLPARAMS)+1000);
  760.             plineCallParams->dwTotalSize = sizeof(LINECALLPARAMS) + 1000;
  761.  
  762.                plineCallParams->dwBearerMode = LINEBEARERMODE_VOICE;
  763.                plineCallParams->dwMediaMode =  LINEMEDIAMODE_DATAMODEM;
  764.                plineCallParams->dwCallParamFlags = LINECALLPARAMFLAGS_IDLE;
  765.                plineCallParams->dwAddressMode    = LINEADDRESSMODE_ADDRESSID;
  766.                plineCallParams->dwAddressID    = 0;
  767.                plineCallParams->dwMinRate    = 1200;
  768.                plineCallParams->dwMaxRate    = 2400;
  769.                             
  770.                lRet = lineMakeCall(myLineInfo[OWNER].hLine,&myCallInfo[0].hCall, 
  771.                                       myCallInfo[0].szDialString ,0,  plineCallParams);
  772.            
  773.             if (lRet > 0)
  774.                {
  775.                wsprintf (buf, "lineMakeCall suceeded!");
  776.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;               
  777.                    myCallInfo[0].dwRequestID = lRet;
  778.                 }
  779.             else 
  780.                {
  781.                    wsprintf ( buf,"lineMakeCall failed, err=x%lx", lRet);
  782.                     lineError(lRet);
  783.                    break;
  784.             }
  785.             
  786.             EndDialog(hDlg, TRUE);        // Exit the dialog
  787.             return (TRUE);
  788.          }
  789.  
  790.             if (   LOWORD(wParam) == IDCANCEL)         // "OK" box selected?
  791.          {
  792.             EndDialog(hDlg, TRUE);        // Exit the dialog
  793.             return (TRUE);
  794.          }
  795.          break;
  796.    }
  797.  
  798.    return (FALSE); 
  799. }
  800.  
  801.  
  802. LRESULT CALLBACK About( HWND hDlg,           
  803.                         UINT message,        
  804.                         WPARAM wParam,       
  805.                         LPARAM lParam)
  806. {
  807.    switch (message) 
  808.    {
  809.        case WM_INITDIALOG: 
  810.                return (TRUE);
  811.  
  812.        case WM_COMMAND:                              
  813.                if (   LOWORD(wParam) == IDOK         
  814.                    || LOWORD(wParam) == IDCANCEL)    
  815.                {
  816.                        EndDialog(hDlg, TRUE);        
  817.                        return (TRUE);
  818.                }
  819.                break;
  820.    }
  821.  
  822.    return (FALSE); 
  823. }
  824.  
  825.  
  826. LRESULT CALLBACK Assist ( HWND hDlg,      // window handle of the dialog box
  827.                         UINT message,       // type of message
  828.                         WPARAM wParam,      // message-specific information
  829.                         LPARAM lParam)
  830. {
  831.    switch (message) 
  832.    {
  833.       case WM_INITDIALOG:  // message: initialize dialog box
  834.          SetDlgItemText(hDlg, IDC_APPNAME,   lineReqMakeCall.szAppName);
  835.          SetDlgItemText(hDlg, IDC_NAME,      lineReqMakeCall.szCalledParty);
  836.          SetDlgItemText(hDlg, IDC_NUMBER,    lineReqMakeCall.szDestAddress);
  837.          SetDlgItemText(hDlg, IDC_COMMENT,   lineReqMakeCall.szComment);     
  838.          return (TRUE);
  839.  
  840.       case WM_COMMAND:   // message: received a command
  841.          if (   LOWORD(wParam) == IDOK )        // "OK" box selected?
  842.          {
  843.             return (TRUE);
  844.          }
  845.       
  846.          if (   LOWORD(wParam) == IDCANCEL)
  847.          {
  848.             EndDialog(hDlg, TRUE);        // Exit the dialog
  849.             return (FALSE);
  850.           }
  851.           break;
  852.       }
  853.  
  854.    return (FALSE); 
  855. }
  856.  
  857.  
  858.  
  859.